package com.shchekoldin.juliet.json;

import com.shchekoldin.juliet.json.codec.decoder.DecodeException;
import com.shchekoldin.juliet.json.codec.decoder.Decoder;
import com.shchekoldin.juliet.json.codec.encoder.Encoder;

public class JsonConverter {

    private static Decoder decoder = new Decoder();

    private Encoder encoder = new Encoder();

    // -------------------------------------------------------
    // -                        LOGIC                        -
    // -------------------------------------------------------

    //
    // API
    //

    public JsonConverter() { }

    public JsonConverter(String profile) {
        setEncoderProfile(profile);
    }

    public void setEncoderProfile(String profile) {
        encoder.setCurrentProfile(profile);
    }

    public void reset() {
        setEncoderProfile(null);
    }

    public String encode(Object obj) {
        return encoder.run(obj);
    }

    public static Object decode(String json) {
        try {
            return decoder.run(json);
        } catch (DecodeException e) {
            e.printStackTrace();
        }

        return null;
    }

}
